﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using PPIDesktopClient.Entities;

namespace PPIDesktopClient.General
{
    public class ConfigReader
    {
        private static volatile ConfigReader _instance = null;
        public static ConfigReader GetInstance()
        {
            if (_instance == null)
            {
                lock (typeof(ConfigReader))
                {
                    if (_instance == null)
                    {
                        _instance = new ConfigReader();
                    }
                }
            }
            return _instance;
        }

        protected ConfigReader()
        {

        }

        public int GetConnectionMode()
        {

            XMLConfigManager _xmlConfigManager = new XMLConfigManager();
            EBaseSettings _xmlApplicationSettings = _xmlConfigManager.ReadBySetting(new EApplicationVersionSetting());

            if (_xmlApplicationSettings.Value == "PRODUCTIVE_PPI")
            {
                return 1;
            }
            else
            {
                if (_xmlApplicationSettings.Value != "BETA")
                {
                    _xmlApplicationSettings.Value = "BETA";
                    _xmlConfigManager.UpdateValue(_xmlApplicationSettings);
                }
                return 0;
            }
        }

        public string GetConnectionString()
        {
            XMLConfigManager _xmlConfigManager = new XMLConfigManager();
            EBaseSettings _xmlApplicationSettings = _xmlConfigManager.ReadBySetting(new EApplicationVersionSetting());


            if (_xmlApplicationSettings.Value == "PRODUCTIVE_PPI")
            {
                return "PRODUCTIVE_PPI";
            }
            else
            {
                if (_xmlApplicationSettings.Value != "BETA")
                {
                    _xmlApplicationSettings.Value = "BETA";
                    _xmlConfigManager.UpdateValue(_xmlApplicationSettings);
                }
                return "BETA";
            }
        }

        public string GetConnectionType()
        {
            XMLConfigManager _xmlConfigManager = new XMLConfigManager();
            EBaseSettings _xmlApplicationSettings = _xmlConfigManager.ReadBySetting(new EApplicationVersionSetting());


            if (_xmlApplicationSettings.Value == "PRODUCTIVE_PPI")
            {
                return "DEV";
            }
            else
            {
                if (_xmlApplicationSettings.Value != "BETA")
                {
                    _xmlApplicationSettings.Value = "BETA";
                    _xmlConfigManager.UpdateValue(_xmlApplicationSettings);
                }
                return "BETA";
            }
        }
    }
}
